package com.bjpowernode.crm.commons.resp;

import com.bjpowernode.crm.commons.enums.RespCode;
import lombok.*;

/**
 * ClassName:Result
 * Package:com.bjpowernode.crm.commons.utils.resp
 * Date:2022/5/31 9:21
 * Description: 应答（响应）结果对象
 * Author:zsm@zhangshuming.com
 */
/*@Getter // 生成get方法
@Setter // 生成set方法
@NoArgsConstructor // 生成无参构造方法
@AllArgsConstructor // 生成带参构造方法*/
@Data // 生成所有的
@NoArgsConstructor
@AllArgsConstructor
@Builder // 链式编程 builder.
public class Result {
    /*应答（响应）码*/
    private Integer code;
    /*应答（响应）消息*/
    private String message;
    /*应答（响应）数据*/
    private Object body;

    // 枚举参数构造方法
    public void setRespCode(RespCode respCode){
        this.code= respCode.getCode();
        this.message= respCode.getText();
    }

    /**
     * 请求成功
     * @return
     */
    public static Result SUCCESS(){
        Result result = new Result();
        /*result.setCode(1000);
        result.setMessage("请求成功");*/
        result.setRespCode(RespCode.SUCCESS);
        result.setBody("");
        return result;
    }

    /**
     * 请求失败
     * @return
     */
    public static Result FRR(){
        Result result = new Result();
        /*result.setCode(9999);
        result.setMessage("请求异常，请稍后重试！");*/
        result.setRespCode(RespCode.FAILURE);
        result.setBody("");
        return result;
    }
}
